﻿@model ItemModel
@using NewLife;
@using NewLife.Cube
@using XCode;
@using XCode.Configuration;
@{
	var name = Model.Name;
	var value = (Boolean)Model.Value;
	var type = Model.Type;

	var atts = HtmlHelper.AnonymousObjectToHtmlAttributes(Model.HtmlAttributes);
	if (!atts.ContainsKey("lay-skin")) atts.Add("lay-skin", "switch");
    if (!atts.ContainsKey("lay-text")) atts.Add("lay-text", "ON|OFF");
    if (!atts.ContainsKey("lay-filter")) atts.Add("lay-filter", name);
	//atts.Add("data-switch", "true");
}
@Html.CheckBox(name, value, atts)
@*<span class="switch">
	<label>
		@Html.CheckBox(name, value, atts)
		<span></span>
	</label>
</span>*@
<script>
layui.use(['form'], function(){
    var form = layui.form;
            //监听指定开关
        form.on('switch(@name)', function(data){
            $("input[name='@name']").val(this.checked);
                //do some ajax opeartiopns;
            });

        layui.form.render(); // 重新渲染。。。
        //修复编辑页面首次加载单选固定为false
    $("input[name='@name']").val(@value.ToString().ToLower());
});
</script>